package org.jeecg.modules.coze.workflow.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.coze.workflow.dto.CozeWorkflowRunDTO;
import org.jeecg.modules.coze.workflow.service.ICozeWorkflowService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Description: Coze工作流控制器
 * @Author: jeecg-boot
 * @Date: 2025-06-28
 * @Version: V1.0
 */
@Api(tags = "Coze工作流接口")
@RestController
@RequestMapping("/coze/workflow")
@Slf4j
public class CozeWorkflowController {

    @Resource
    private ICozeWorkflowService cozeWorkflowService;

    /**
     * 运行Coze工作流
     *
     * @param dto 工作流参数
     * @return
     */
    @ApiOperation(value = "运行Coze工作流", notes = "运行Coze工作流")
    @PostMapping(value = "/run", consumes = { "application/json" })
    public Result<JSONObject> runWorkflow(@Valid @RequestBody CozeWorkflowRunDTO dto) {
        try {
            return cozeWorkflowService.runWorkflow(dto);
        } catch (Exception e) {
            log.error("运行Coze工作流失败", e);
            return Result.error("运行失败：" + e.getMessage());
        }
    }
}